package com.xxtx.trade.web.noticeController;

import com.alibaba.fastjson.JSON;
import com.xxtx.trade.common.util.SpringUserContext;
import com.xxtx.trade.common.util.model.Result;
import com.xxtx.trade.notice.dto.AgentNoticeDto;
import com.xxtx.trade.notice.service.NoticeService;
import com.xxtx.trade.sysUser.vo.TradeSysUserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/v1/xxtx/agentNotice")
public class AgentNoticeController {
    @Autowired
    private NoticeService noticeService;
    @Autowired
    private SpringUserContext springUserContext;
    /**
     * 查看代理商个人公告列表
     */
    @RequestMapping(value = "/list",method = RequestMethod.POST)
   public Result<Object> deleteUserInfo(@RequestBody AgentNoticeDto noticeDto){
        //获取当前登录用户信息
        Result<Object> result1 = new Result<>();
        try {
            TradeSysUserVo loginUser = springUserContext.getCurrentLoginUser();
            noticeDto.setAccountName(loginUser.getAccountName());
            result1 = noticeService.selectAgentNotice(noticeDto);
        } catch (Exception e) {
            return new Result<>(400,"当前用户异常登录,请重新登录","fail",null);
        }
        return result1;
    }
    /**
     * 删除代理商个人公告列表
     */
    @RequestMapping(value = "/delete",method = RequestMethod.POST)
   public Result<Object> selectUserInfo(@RequestBody AgentNoticeDto noticeDto){
        //获取当前登录用户信息
        try {
            TradeSysUserVo loginUser = springUserContext.getCurrentLoginUser();
            noticeDto.setAccountName(loginUser.getAccountName());
        } catch (Exception e) {
            return new Result<>(400,"当前用户异常登录,请重新登录","fail",null);
        }
        Result<Object> result = noticeService.deleteAgentNotice(noticeDto);
        return result;
    }
    /**
     * 代理商标记为已读
     */
    @RequestMapping(value = "/udapte",method = RequestMethod.POST)
   public Result<Object> updateUserInfo(@RequestBody AgentNoticeDto noticeDto){
        Result<Object> result = new Result<>();
        try {
            result=noticeService.updateAgentNotice(noticeDto);
        }catch (Exception e){
            result.setMessage("标记已读失败");
            result.setCode(400);
        }
        return result;
    }
    /**
     * 代理商的最新一条公告
     */
    @RequestMapping(value = "/new/notice",method = RequestMethod.POST)
   public Result<Object> selectNewUserInfo(@RequestBody AgentNoticeDto noticeDto){
        Result<Object> result = new Result<>();
        try {
            result=noticeService.selectNewAgentNotice(noticeDto);
        }catch (Exception e){
            result.setMessage("查询最新一条公告失败");
            result.setCode(400);
        }
        return result;
    }
}
